package com.example.entity;


import com.example.entity.vo.algorithmconfig.CoverAlgorithmConfig;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 遮盖脱敏模式枚举
 */
@Getter
@AllArgsConstructor
public enum CoverModeEnum {
    RETAIN_PREFIX_SUFFIX("保留前后", "保留前{prefix}后{suffix}，遮盖字符{maskChar}"),
    RETAIN_BETWEEN("保留范围", "保留第{start}到{end}，遮盖字符{maskChar}"),
    MASK_PREFIX_SUFFIX("遮盖前后", "遮盖前{prefix}后{suffix}，遮盖字符{maskChar}"),
    MASK_BETWEEN("遮盖范围", "遮盖第{start}到{end}，遮盖字符{maskChar}"),
    MASK_BEFORE_KEYWORD("关键词前遮盖", "{keyword}前遮盖，遮盖字符{maskChar}"),
    MASK_AFTER_KEYWORD("关键词后遮盖", "{keyword}后遮盖，遮盖字符{maskChar}");

    /**
     * 中文名称
     */
    private final String label;
    /**
     * 描述模板
     */
    private final String descTemplate;

    /**
     * 根据配置生成描述信息
     */
    public String generateDesc(CoverAlgorithmConfig config) {
        String desc = descTemplate;
        if (config == null) {
            return "";
        }

        return desc
                .replace("{prefix}", safe(config.getPrefix()))
                .replace("{suffix}", safe(config.getSuffix()))
                .replace("{start}", safe(config.getStart()))
                .replace("{end}", safe(config.getEnd()))
                .replace("{keyword}", safe(config.getKeyword()))
                .replace("{maskChar}", safe(config.getMaskChar()));
    }

    private String safe(Object o) {
        return o == null ? "-" : o.toString();
    }
}
